package com.hsxc.cdz.monitor.bean.second;

import com.hsxc.cdz.base.util.BytesUtil;

/**
 * 直流桩报文的实体类
 * @author llw
 *
 */
public abstract class SecMessage {
	/*****************************************************/
	//对象私有属性
	private byte version; //版本号
	private int pileIndex;  //桩发送序号
	private int serIndex;   //服务器发送序号
	private String pileNO;  //桩编号
	private byte frame;      //报文帧类型
	
	//类常量
	public static final String isStart = "0xfe";
	public static final String isEnd = "0x10";
    // 版本号作为变量长驻内存  通过set() and get()改变  
    //记得加对象锁  锁住对应的变量synchronized(finalversion) 
	public static byte final_version = 2;  
	public static int final_FateVersion = 2;
	public static int final_PileFate = 2;
	public static int final_ServiceFate = 2;
	public static Fate final_fate;  
	//字段长度
	public static final int length_length = 2;
	public static final int length_crc = 1;
	public static final int length_version = 1;
	public static final int length_pileIndex = 2;
	public static final int length_seIndex = 2;
	public static final int length_pileNO = 8;
	public static final int length_frame = 1;
	public static final int length = 14;
	
	public static final byte frame_heart_pile = 5;
	public static final byte frame_heart_ser = 6;
	public static final byte frame_bill_pile = 9;
	public static final byte frame_bill_ser = 10;
	public static final byte frame_charge_pile = 21;
	public static final byte frame_charge_ser = 22;
	/********************************************************/
	//抽象方法
	public abstract byte[] getMessage();
	public abstract boolean execute();
	public void setMessage(byte[] data){
		int temp = 0;
		this.setVersion(data[temp]);
		temp = temp+length_version;
		this.setSerIndex(BytesUtil.bytesToIntDesc(BytesUtil.getByte(temp,length_seIndex, data)));
		temp = temp+length_seIndex;
		this.setPileIndex(BytesUtil.bytesToIntDesc(BytesUtil.getByte(temp, length_pileIndex, data)));
		temp = temp+length_pileIndex;
		this.setPileNO(BytesUtil.bcdBytesToStr(BytesUtil.getByte(temp, length_pileNO, data)));
		temp = temp+length_pileNO;
		this.setFrame((data[temp]));
	}
	/*****************************************************/
	//get() and set()
	public int getPileIndex() {
		return pileIndex;
	}
	public byte getVersion() {
		return version;
	}
	public void setVersion(byte version) {
		this.version = version;
	}
	public void setPileIndex(int pileIndex) {
		this.pileIndex = pileIndex;
	}
	public int getSerIndex() {
		return serIndex;
	}
	public void setSerIndex(int serIndex) {
		this.serIndex = serIndex;
	}
	public String getPileNO() {
		return pileNO;
	}
	public void setPileNO(String pileNO) {
		this.pileNO = pileNO;
	}
	public byte getFrame() {
		return frame;
	}
	public void setFrame(byte frame) {
		this.frame = frame;
	}
}
